package array;

import java.util.ArrayList;
import java.util.List;

public class leetCode47_permuteUnique {
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> permuteUnique(int[] nums) {
       if(nums == null || nums.length == 0) return res;
       List<Integer> trace = new ArrayList<>();
       boolean[] booleans = new boolean[nums.length];
       build(nums,trace,booleans);
       return res;
    }

    public void build(int[] nums, List<Integer> trace,boolean[] booleans){
        if(nums.length == trace.size() && !res.contains(trace)){
            res.add(new ArrayList<>(trace));
            return;
        }

        for (int i = 0; i < nums.length; i++) {
            if(booleans[i]){
                continue;
            }
            trace.add(nums[i]);
            booleans[i] = true;
            build(nums,trace,booleans);
            trace.remove(trace.size() - 1);
            booleans[i] = false;
        }
    }






}
